package com.bobo.demo.Thread;


//静态代理模式总结
//真实对象和代理兑现都要实现同一个接口
//代理对象要代理真实角色

//好处：
    //代理对象可以做很多真实对象做不了的事情
    //真实对象专注做自己的
public class StaticProxy {
    public static void main(String[] args) {

        new Thread( () -> System.out.println("gogogo") ).start(); //同样 Thread 和 Runnable 也是使用了代理模式 都实现了run()方法
        new WeddingCompany(new You()).HapppyMarry();
    }
}

interface Marry {
    void HapppyMarry();
}

//真实角色
class You implements Marry {

    @Override
    public void HapppyMarry() {
        System.out.println("I feel Happy，Because i am married");
    }
}

//代理角色，帮助你结婚
class WeddingCompany implements Marry {

    //代理 -> 真实角色
    private Marry target;

    public WeddingCompany(Marry target) {
        this.target = target;
    }

    @Override
    public void HapppyMarry() {
        before();
        this.target.HapppyMarry();
        after();
    }

    private void after() {
        System.out.println("The wedding is end that you need to pay!");
    }

    private void before() {
        System.out.println("The wedding is going to begin.Go and dress up!");
    }

}